﻿//----------------------------------------------------------------------------------------------------
// radial menu buttons
//----------------------------------------------------------------------------------------------------

package HG.Visual
{
	import flash.display.*;
	import flash.events.*;
	import flash.utils.Timer;
	
	import HG.GameService;
	
	public class RadialButton extends MovieClip
	{
		var m_isOpen:Boolean;
		var m_animTimer:Timer;
		var m_actionID:Number;
		
		var m_hovered:Boolean;
		
		//----------------------------------------------------------------------------------------------------
		public function RadialButton() 
		{
			stop();
			
			m_animTimer = new Timer(0);
			m_animTimer.addEventListener(TimerEvent.TIMER, SetOpenInternal);
			
			
		}
		
		//----------------------------------------------------------------------------------------------------
		public function OnHover(evt:Event)
		{
			if (m_hovered)
				return;
			
			m_hovered = true;
			this.Content.gotoAndPlay('in');
		}
		
		//----------------------------------------------------------------------------------------------------
		public function OnUnHover(evt:Event)
		{
			if(!m_hovered)
				return;
				
			m_hovered = false;
			this.Content.gotoAndPlay('out');
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetOpen(vis:Boolean, delay:Number) 
		{
			if (m_isOpen == vis)
				return;
			
			m_isOpen = vis;
			
			if (m_isOpen)
			{
				this.gotoAndStop('hide');
				this.visible = false;
			}
			
			if (m_animTimer)
				m_animTimer.stop();
			
			if (delay > 0)
			{
				m_animTimer.delay = delay;
				m_animTimer.start();
			}
			else
			{
				SetOpenInternal(null);
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetRotation(rot:Number)
		{
			this.rotation = rot;
			this.Content.Content.Icon.rotation = -rot;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetActionID(actionID:Number)
		{
			m_actionID = actionID;
			this.Content.Content.Icon.gotoAndStop(actionID);
		}
		
		//----------------------------------------------------------------------------------------------------
		public function GetActionID():Number
		{
			return m_actionID;
		}
		
		//----------------------------------------------------------------------------------------------------
		public function SetOpenInternal(evt:TimerEvent) 
		{
			m_animTimer.stop();
			
			if (m_isOpen)
			{
				this.visible = true;
				this.gotoAndPlay('in');
			}
			else
			{
				this.gotoAndPlay('out');
			}
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}